<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
	Name	: Project class controller
	Author	: Iswan Putera S.Kom
	Date	: 02-11-2013
	Version : 1.0.0
*/

class Project extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->load->library('zetro_auth');
		$this->load->model('main_model');
		$this->zetro_auth->check_login();
		//force_ssl();
	}
	function View($filename,$data)
	{
		$this->load->view('admin/header');
		$this->load->view('outsourcing/'.$filename,$data);
		$this->load->view('admin/footer');
	}
	function listproject()
	{
		$this->zetro_auth->menus('list_project');
		$data['tab_header']=$this->zetro_form->generate_tab_header('List Project');
		$this->zetro_form->frm_file('asset/frm/zetro_project.frm');
		$content='';
		$this->zetro_form->section('headproject');
		$data['lok'] =$this->zetro_form->generate_dropdown_content('project_customer','id_customer','nm_customer');
		$data['lok2'] =$this->zetro_form->generate_dropdown_content('lokasi','id_lokasi','nm_lokasi');
		$data['frm3']=$this->zetro_form->frmInline('frm2',true,false,true);
		//list project
		$this->zetro_form->section('project');
		$this->zetro_form->action_col(true);
		$this->zetro_form->tabel_content($content);
		$data['list']=$this->zetro_form->list_std();
		//add project
		$this->zetro_form->addButtons();
		$this->zetro_form->section('projectfrm');
		$this->zetro_auth->menus('add_new_project');
		$this->zetro_form->buttons(($this->zetro_auth->cek_oto('c')!='')?true:false,'Simpan');
		//load view
		$data['modal']=$this->zetro_form->dialog($this->zetro_form->frm_std('frm1'),'Add New Project');
		$this->View('project_list',$data);
	}
	function getprojectlist()
	{
		$data=array();$n=0;$content='';
		$where='';
		$ordby=empty($_POST['ordby'])?'nm_member':$_POST['ordby'];
		$this->main_model->table_name('project_list_view');
		$this->main_model->query();
		if(empty($_POST['cari']))
		{
			(empty($_POST['id_customer'])||$_POST['id_customer']=='')?'':
			$this->main_model->where(array('id_customer'=>$_POST['id_customer']));
		}else{
			$this->main_model->where_like('nm_customer',$_POST['cari'],'after');
		}/*
		//$this->main_model->orderby($ordby);*/
		$this->main_model->set_methods('select');
		$lst_usr=$this->main_model->set_data();
		$this->zetro_auth->menus('list_project');
		foreach($lst_usr as $r)
		{
			$n++;
		$icon=($this->zetro_auth->cek_oto('e')!='')?
		$this->zetro_form->z_icon($r->id_project,array('cus-folder','cus-cross'),array('update','deleted')):"";
		$content.= tr().td($n,'',false,'','center').
				 td($r->nm_project).
				 td($r->nm_lokasi).
				 td($r->nm_customer).
				 td($r->periode." Hari",'',false,'','right').
				 td($r->stat_project,'',false,'','center').
				 td($icon,'',false,'','center').
				_tr();	
		}
		$content.=$this->zetro_form->DataNotFound($lst_usr,6);
		echo $content;
		
	}
	
	function setproject()
	{
		$data=array();
		$data['id_project']=empty($_POST['id_project'])?'0':$_POST['id_project'];
		$data['nm_project']=empty($_POST['nm_project'])?'':$_POST['nm_project'];
		$data['id_customer']=empty($_POST['id_customer'])?'0':$_POST['id_customer'];
		$data['id_lokasi']=empty($_POST['id_lokasi'])?'0':$_POST['id_lokasi'];
		$data['start_project']=empty($_POST['start_project'])?'':tgltoSql($_POST['start_project']);
		$data['end_project']=empty($_POST['end_project'])?'':tgltoSql($_POST['end_project']);
		$data['val_project']=empty($_POST['val_project'])?'0':str_replace(",","",$_POST['val_project']);
		$data['tgl_project']=empty($_POST['tgl_trans'])?date('Ymd'):tgltoSql($_POST['tgl_trans']);
		$data['stat_project']=empty($_POST['stat_project'])?'N':$_POST['stat_project'];
		$data['created_by']=$this->session->userdata('userid');
		$this->main_model->prepared_data('project',$data);
		echo success($this->main_model->set_data());		
	}
	
	function getdetailproject()
	{
		$data=array();
		$id=$_POST['id'];
		$this->main_model->table_name('project_list_view');
		$this->main_model->set_methods('select');
		$this->main_model->query();
		$this->main_model->where(array('id_project'=>$id));
		$data=$this->main_model->set_data();
		echo json_encode($data[0]);
	}
	
	function deleteproject()
	{
		$id=$_POST['id'];
		$this->main_model->table_name('project');
		$this->main_model->set_methods('delete');
		$this->main_model->where(array('id_project'=>$id));
		$this->main_model->set_data();	
	}
	//customer data
	function customer()
	{
		$this->zetro_auth->menus('list_customer');
		$data['tab_header']=$this->zetro_form->generate_tab_header('Customer');
		$this->zetro_form->frm_file('asset/frm/zetro_project.frm');
		$content='';
		//list project
		$this->zetro_form->section('customer');
		$this->zetro_form->action_col(true);
		$this->zetro_form->tabel_content($content);
		$data['list']=$this->zetro_form->list_std();
		//add project
		$this->zetro_form->addButtons();
		$this->zetro_form->section('customerfrm');
		$this->zetro_auth->menus('add_customer');
		$this->zetro_form->buttons(($this->zetro_auth->cek_oto('c')!='')?true:false,'Simpan');
		//load view
		$data['modal']=$this->zetro_form->dialog($this->zetro_form->frm_std('frm1'),'Add New ustomer');
		$this->View('project_customer',$data);
		
	}
	
	function setcustomer()
	{
		$data=array();
		$data['id_customer']=empty($_POST['id_customer'])?'0':$_POST['id_customer'];
		$data['nm_customer']=empty($_POST['nm_customer'])?'':$_POST['nm_customer'];
		$data['add_customer']=empty($_POST['add_customer'])?'':$_POST['add_customer'];
		$data['telp_customer']=empty($_POST['telp_customer'])?'':$_POST['telp_customer'];
		$data['cp_customer']=empty($_POST['cp_customer'])?' ':$_POST['cp_customer'];
		$data['created_by']=$this->session->userdata('userid');
		$this->main_model->prepared_data('project_customer',$data);
		echo success($this->main_model->set_data());		
	}
	function getlistcustomer()
	{
		$data=array();$n=0;$content='';
		$where='';
		$ordby=empty($_POST['ordby'])?'nm_customer':$_POST['ordby'];
		$this->main_model->table_name('project_customer');
		$this->main_model->query();
		$this->main_model->where();
		$this->main_model->orderby($ordby);
		$this->main_model->set_methods('select_ordered');
		$lst_usr=$this->main_model->set_data();
		$this->zetro_auth->menus('list_customer');
		foreach($lst_usr as $r)
		{
			$n++;
		$icon=($this->zetro_auth->cek_oto('e')!='')?
			$this->zetro_form->z_icon($r->id_customer,array('cus-folder','cus-cross'),array('update','deleted')):
				  "";
		$content.= tr().td($n,'',false,'','center').
				 td($r->nm_customer).
				 td($r->add_customer).
				 td($r->telp_customer).
				 td($r->cp_customer).
				 td($icon,'',false,'','center').
				_tr();	
		}
		$content.=$this->zetro_form->DataNotFound($lst_usr,6);
		echo $content;
		
	}
	
	function getdetailcustomer()
	{
		$data=array();
		$id=$_POST['id'];
		$this->main_model->table_name('project_customer');
		$this->main_model->set_methods('select');
		$this->main_model->query();
		$this->main_model->where(array('id_customer'=>$id));
		$data=$this->main_model->set_data();
		echo json_encode($data[0]);	
	}
	
	function deletecustomer()
	{
		$id=$_POST['id'];
		$this->main_model->table_name('project_customer');
		$this->main_model->set_methods('delete');
		$this->main_model->where(array('id_customer'=>$id));
		$this->main_model->set_data();	
		
	}
//end of class
}